package com.big.merchan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.common.exception.BigException;
import com.big.common.result.ResultCodeEnum;
import com.big.merchan.mapper.MerchandiseOffersMapper;
import com.big.merchan.service.MerchandiseOffersService;
import com.big.model.model.merchandise.MerchandiseOffers;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 优惠业务
 */
@Service
@Slf4j
@Transactional
public class MerchandiseOffersServiceImpl extends ServiceImpl<MerchandiseOffersMapper, MerchandiseOffers> implements MerchandiseOffersService {


    /**
     * 优惠列表
     * @return
     */
    @Override
    public List<MerchandiseOffers> merchandiseOffersInfos(String mId) {
        QueryWrapper<MerchandiseOffers>queryWrapper =new QueryWrapper<>();
        if(!StringUtils.isEmpty(mId)){
            queryWrapper.eq("m_id",mId);
        }
        return  baseMapper.selectList(queryWrapper);
    }


    @Override
    public Integer SaveOffers(List<MerchandiseOffers> offers) {

        Integer io=0;
        for (int i = 0; i < offers.size(); i++) {
             baseMapper.insert(offers.get(i));
            io++;
        }
        if(io!=offers.size()){
          throw  new BigException(ResultCodeEnum.DATA_ERROR);
        }
        return io;
    }


}


